#ifndef __QpwPackages__
#define __QpwPackages__

#include <QtCore/QUuid>
#include <QtCore/QPointF>
#include <QpwNetwork.h>

namespace QpwPackages {

enum Types {
    InvalidPackage,
    PosChangePackage = QpwNetwork::VariantDatagram::CustomVariantDataType,
    MakeObjectPackage,
    DestroyObjectPackage,
    PlayerControlPackage
};

class PosChange : public QpwNetwork::VariantDatagram {
public:
    explicit PosChange( const QUuid & uuid, const QPointF & pos, qreal rotation )
        : QpwNetwork::VariantDatagram( PosChangePackage, uuid.toString(), pos, rotation ) {}

    QUuid uuid() const { return QUuid( data[0].toString() ); }
    QPointF pos() const { return data[1].toPointF(); }
    qreal rotation() const { return data[2].toDouble(); }

};

class MakeObject : public QpwNetwork::VariantDatagram {
public:
    explicit MakeObject( const QUuid & uuid, const QUuid & subTypeUuid )
        : QpwNetwork::VariantDatagram( MakeObjectPackage, uuid.toString(), subTypeUuid.toString() ) {}

    QUuid uuid() const { return QUuid( data[0].toString() ); }
    QUuid subTypeUuid() const { return QUuid( data[1].toString() ); }

};

class DestroyObject : public QpwNetwork::VariantDatagram {
public:
    explicit DestroyObject( const QUuid & uuid )
        : QpwNetwork::VariantDatagram( DestroyObjectPackage, uuid.toString() ) {}

    QUuid uuid() const { return QUuid( data[0].toString() ); }

};

class PlayerControl : public QpwNetwork::VariantDatagram {
public:
    enum ControlType {
        BeginMoving,
        EndMoving,
        ChangeDirection
    };
    explicit PlayerControl() : QpwNetwork::VariantDatagram(InvalidPackage) {}
    explicit PlayerControl( ControlType controlType  )
        : QpwNetwork::VariantDatagram( PlayerControlPackage, quint32(controlType) ) {}
    explicit PlayerControl( ControlType controlType, qreal direction )
        : QpwNetwork::VariantDatagram( PlayerControlPackage, quint32(controlType), direction ) {}

    static PlayerControl beginMoving( qreal movingDirection )
            { return PlayerControl( BeginMoving, movingDirection ); }
    static PlayerControl endMoving() { return PlayerControl(EndMoving); }
    static PlayerControl changeDirection( qreal direction )
        { return PlayerControl( ChangeDirection, direction ); }

    ControlType controlType() const { return ControlType( data[0].toUInt() ); }
    qreal direction() const { return data[1].toDouble(); }

};

};

#endif//__QpwPackages__
